public class OperatorFile {
	private java.net.Socket socket;
	private String data;
	private java.util.Vector dataList;
	private String copyTo;
	public java.util.Vector getDataList() {
		return dataList;
	}

	public void setDataList(java.util.Vector dataList) {
		this.dataList = dataList;
	}
 
	public OperatorFile(java.net.Socket s,String d,String copy){
		this.socket = s;
		this.data = d;
		this.copyTo=copy;
		opfile();
	}
	
	public void opfile(){
		if(this.socket!=null){
			try{
				//output
				java.io.OutputStream out = socket.getOutputStream();
				out.write((data+"   \r\n").getBytes());
				out.flush();
				//input
				java.io.InputStream input = socket.getInputStream();
				char pathOrFile=(char)input.read();
				System.out.println(pathOrFile);
				if(pathOrFile=='p'){
					java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(input));
					String data=null;
					java.util.Vector dlist = new java.util.Vector();
	
					while(!(data=br.readLine()).equals("end")){
						if(!data.trim().equals("")){
							System.out.println(data);
							dlist.add(data);
						}
					}
					this.setDataList(dlist);
				}
				if(pathOrFile=='f'){
					new Thread(new CopyFile(data,input,copyTo)).start();
				}
				
			}catch(Exception e){
				e.printStackTrace();
			}
			finally{
				try{
					socket.close();
				}catch(Exception e){
					e.printStackTrace();
				}

			}
			
			
		}
	}
}
